﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace InstrumentationLibrary.Config
{
    /// <summary>
    /// Aspect element collection, contains a collection of aspects details.
    /// </summary>
    public class AspectElementCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new AspectElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((AspectElement)element).Name;
        }

        public IInstrumentationAspect this[string aspectName]
        {
            get
            {
                foreach (AspectElement item in this)
                {
                    if (item.Name == aspectName)
                    {
                        return item.CreateAspect();
                    }
                }

                throw new InvalidOperationException(
                    string.Format("aspect {0} does not exist in the catalog", aspectName));
            }
        }
    }
}
